<template>
  <div class="my-menu">
    <el-menu
      :default-active="defaultMenu"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      background-color="#000"
      text-color="#fff"
      active-text-color="#fff"
      router
      :default-openeds="[menuData[3].router]"
    >
      <div v-for="(item,index) in menuData" :key="index">
        <div v-if="item.onTips">
          <el-badge  :value="12" class="item" v-if="item.menuChild.length == 0">
          <el-menu-item :index="item.router" >
            <i class="el-icon-menu"></i>
            <span slot="title">{{item.menuTxt}}</span>
          </el-menu-item>
        </el-badge>
        <el-submenu v-else :index="item.router">
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span slot="title">{{item.menuTxt}}</span>
          </template>
          <el-menu-item-group>
            <el-menu-item
              v-for="(childItem,childIndex) in item.menuChild"
              :key="childIndex"
              :index="childItem.router"
            >{{childItem.menuTxt}}</el-menu-item>
            <!-- <el-menu-item index="4-1">广告数据</el-menu-item>
          <el-menu-item index="4-2">广告素材</el-menu-item>
            <el-menu-item index="4-3">新增小模版</el-menu-item>-->
          </el-menu-item-group>
        </el-submenu>
        </div>
        <div v-else>
          <!-- <el-badge is-dot class="item" v-if="item.menuChild.length == 0"> -->
          <el-menu-item v-if="item.menuChild.length == 0" :index="item.router" >
            <i class="el-icon-menu"></i>
            <span slot="title">{{item.menuTxt}}</span>
          </el-menu-item>
        <!-- </el-badge> -->
        <el-submenu v-else :index="item.router">
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span slot="title">{{item.menuTxt}}</span>
          </template>
          <el-menu-item-group>
            <el-menu-item
              v-for="(childItem,childIndex) in item.menuChild"
              :key="childIndex"
              :index="childItem.router"
            >{{childItem.menuTxt}}</el-menu-item>
            <!-- <el-menu-item index="4-1">广告数据</el-menu-item>
          <el-menu-item index="4-2">广告素材</el-menu-item>
            <el-menu-item index="4-3">新增小模版</el-menu-item>-->
          </el-menu-item-group>
        </el-submenu>
        </div>
        <!-- <el-badge is-dot class="item" v-if="item.menuChild.length == 0">
          <el-menu-item v-if="item.menuChild.length == 0" :index="item.router" >
            <i class="el-icon-menu"></i>
            <span slot="title">{{item.menuTxt}}</span>
          </el-menu-item>
        </el-badge>
        <el-submenu v-else :index="item.router">
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span slot="title">{{item.menuTxt}}</span>
          </template>
          <el-menu-item-group>
            <el-menu-item
              v-for="(childItem,childIndex) in item.menuChild"
              :key="childIndex"
              :index="childItem.router"
            >{{childItem.menuTxt}}</el-menu-item>
            <!-- <el-menu-item index="4-1">广告数据</el-menu-item>
          <el-menu-item index="4-2">广告素材</el-menu-item>
            <el-menu-item index="4-3">新增小模版</el-menu-item>-->
          <!-- </el-menu-item-group> -->
        <!-- </el-submenu> -->
      </div>
      <!-- <el-submenu
        v-for="(item,index) in menuData"
        :key="index"
        :index="item.router"
        :route="item.router"
      >
        <template slot="title">
          <i class="el-icon-menu"></i>
          <span slot="title">{{item.menuTxt}}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            v-for="(childItem,childIndex) in item.menuChild"
            :key="childIndex"
            :index="childItem.router"
            :route="childItem.router"
      >{{childItem.menuTxt}}</el-menu-item>-->
      <!-- <el-menu-item index="4-1">广告数据</el-menu-item>
          <el-menu-item index="4-2">广告素材</el-menu-item>
      <el-menu-item index="4-3">新增小模版</el-menu-item>-->
      <!-- </el-menu-item-group>
      </el-submenu>-->
      <!-- <el-menu-item index="1">
        <i class="el-icon-menu"></i>
        <span slot="title">主页</span>
      </el-menu-item>
      <el-menu-item index="2">
        <i class="el-icon-document"></i>
        <span slot="title">报告</span>
      </el-menu-item>
      <el-menu-item index="3">
        <i class="el-icon-setting"></i>
        <span slot="title">设备</span>
      </el-menu-item>
      <el-submenu index="4">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>广告</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="4-1">广告数据</el-menu-item>
          <el-menu-item index="4-2">广告素材</el-menu-item>
          <el-menu-item index="4-3">新增小模版</el-menu-item>
        </el-menu-item-group>
      </el-submenu>-->
    </el-menu>
  </div>
</template>

<script>
export default {
  name: 'myMenu',
  props: {
    menuData: {
      type: Array
    }
  },
  data () {
    return {}
  },
  computed: {
    defaultMenu () {
      // console.log(this.$route)
      return this.$route.path
    }
  },
  created () {},
  mounted () {},
  watch: {},
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    }
  },
  components: {}
}
</script>

<style scoped lang="less">
@import url("./index.less");
</style>
<style>
.el-menu-item.is-active {
  background-color: #ef7e09 !important;
}
.item {
  width: 100%;
}
.el-badge__content.is-fixed.is-dot {
  right: 124px !important;
}
.el-badge__content.is-fixed {
  top: 15px !important;
  right: 50% !important;
}

</style>
